using System;
using System.Drawing;
using System.ComponentModel;

namespace Camalon.Drawing
{
    /// <summary>
    /// The FillTile structure is used on <see cref="LinearGradientFill"/> and <see cref="PathGradientFill"/> objects to to tile the shape fill. The Tile property takes a
    /// FillTile structure with TileX value for horizontal tiling and TileY value for vertical tiling. The TileRelative flag
    /// determines the tile mode, whether an absolute or a relative tiling should occur. If the <c>TileRelative</c> property is set
    /// true, the TileX and TileY values will be measured in percent, otherwise the TileX and TileY values are measured
    /// in pixels, to paint the the tiling area of the shape fill.
    /// </summary>
	[TypeConverter(typeof(FillTileConverter))]
	public struct FillTile
	{
		int			_tileX;
		int			_tileY;
		bool		_tileRelative;    

		public FillTile(int tileX, int tileY ):this( tileX, tileY, true){}

		public FillTile(int tileX, int tileY, bool tileRelative)
		{
			if( tileX < 0 ) tileX= 0;
			if( tileY < 0 ) tileY= 0;

			_tileX			= tileX;
			_tileY			= tileY;
			_tileRelative	= tileRelative;
		}

		#region operatoren
		public override bool Equals(object obj)
		{
			if(!( obj is FillTile)) return false;

			return  this == (FillTile)obj;
		}

		public bool Equals(FillTile value)
		{
			return  this == value;
		}

		public override int GetHashCode()
		{
			return _tileX.GetHashCode()^_tileY.GetHashCode()^_tileRelative.GetHashCode();
		}

		public static bool operator ==(	FillTile value1,FillTile value2	)
		{
			return 
				value1._tileX == value2._tileX && 
				value1._tileY == value2._tileY && 
				value1._tileRelative == value2._tileRelative ;
		}

		public static bool operator !=(	FillTile value1,FillTile value2	)
		{
			return !(value1== value2);
		}
		#endregion operatoren

        /// <summary>
        /// Gets the empty FillTile structure.
        /// </summary>
        /// <value>The empty FillTile structure.</value>
		public static FillTile Empty
		{
			get{ return new FillTile(0,0,true);}
		}


		[Browsable(false)]
		public bool IsEmpty
		{
			get{ return _tileX == 0 && _tileY == 0;}
		}

		[DefaultValue( 0 )]
		public int TileX
		{
			get{ return _tileX;  }
			set
			{ 
				if( value < 0 ) value = 0;
				if( value == _tileX) return;
				_tileX = value;
			}
		}

		[DefaultValue( 0 )]
		public int TileY
		{
			get{ return _tileY;  }
			set
			{ 
				if( value < 0 ) value = 0;
				if( value == _tileY) return;
				_tileY = value;
			}
		}

		[DefaultValue( true )]
		public bool TileRelative
		{
			get{ return _tileRelative;}
			set
			{ 
				if( value == _tileRelative) return;
				_tileRelative = value;
			}
		}
		
	}


}
